
"""
Created on Tue Feb 19 14:55:43 2013

@author: aponteeduarddo@gmail.com
Copyright Eduardo Aponte 2013.
"""

from mex_binder import binder_py

eyelink_data_switch = binder_py('mx_eyelink_data_switch')
eyelink_data_switch.mx_c.headers = ['<eyelink.h>','"mex.h"','"utils.h"']
eyelink_data_switch.bindo += ['utils.o']
eyelink_data_switch.mx_c.code = \
"""
INT16 _main( UINT16 flag )
{
    return eyelink_data_switch( flag ); 
}

void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
    mwSize td[2] = {1,1};
    double *status;
    int iv;
    
    /* Verify input arguments. */
    if( nrhs != 1 ) {
        mexErrMsgTxt("Incorrect number of inputs.");
    } else if( nlhs > 1 ) {
        mexErrMsgTxt("Too many output arguments.");
    }
    
    
    if ( isscalar( *prhs ) ){
       
       if (returnscalar( prhs[0], &iv ) != 1 )
            mexErrMsgTxt("Complex data is not supported.");                     
       if ( iv < 0 )
            mexErrMsgTxt("flag should be positive.");
    } else {
         mexErrMsgTxt("flag should be scalar.");
    } 

    plhs[0] = mxCreateNumericArray( 2, td, mxDOUBLE_CLASS, mxREAL);
    status = mxGetPr(plhs[0]);

    *status = (double ) _main( (UINT16 ) iv );
        
    return;
}
"""

eyelink_data_switch.mx_c.mdoc = \
"""function [ ] = mx_eyelink_data_switch( )
%MX_EYELINK_DATA_SWITCH Sets what data from tracker will be accepted and 
% placed in queue.
%
% Remarks:
% This does not start the tracker recording, and so can be used with 
% eyelink_broadcast_open(). It also does not clear old data from the queue. The
% data is set with a bitwise OR of these flags: RECORD_LINK_SAMPLES - send 
% samples on link. RECORD_LINK_EVENTS - send events on link.
% Parameters:
% flags 	Bitwise OR flags.
% Returns:
% 0 if OK else link error.
%
"""
eyelink_data_switch.write_c()
eyelink_data_switch.write_m()
eyelink_data_switch.compile()
eyelink_data_switch.write_sh()

